﻿using DryWCS.App.Common;
using DryWCS.App.ViewModel;
using DryWCS.Service.GlobalVariable;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace DryWCS.App
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        private System.Timers.Timer polling1000 = new System.Timers.Timer(1000);

        public MainWindow()
        {
            InitializeComponent();
            this.DataContext = new MainViewModel();
            polling1000.Elapsed += Polling1000_Elapsed;
            polling1000.Start();
        }

        private void Polling1000_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            Application.Current?.Dispatcher.Invoke(() =>
            {
                //cb_flatcar.IsChecked = GV.FlatcarIsLock;
                cb_stacker.IsChecked = GV.StackerIsLock;
            });
        }

        private void Minimize_Click(object sender, RoutedEventArgs e)
        {
            this.WindowState = WindowState.Minimized;
        }

        private void Exit_Click(object sender, RoutedEventArgs e)
        {


            bool res = Msg.Question("是否确认退出程序？");

            if (res == false)
            {
                return;
            }

            Environment.Exit(0);
        }

        private void flatcarlockSwitch(object sender, RoutedEventArgs e)
        {
            CheckBox cb = sender as CheckBox;
            GV.FlatcarIsLock = cb.IsChecked == true;
        }

        private void stackerlockSwitch(object sender, RoutedEventArgs e)
        {
            CheckBox cb = sender as CheckBox;
            GV.StackerIsLock = cb.IsChecked == true;
        }
    }
}
